﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace psafth.AMB.Objects
{
    public class ReceiverObject
    {
        public AMBMessageType MessageType
        {
            get;
            set;
        }

        public List<DataObject> Data
        {
            get;
            private set;
        }

        public AMBMessage Message
        {
            get;
            private set;
        }


        public ReceiverObject(byte[] byteArray)
        {
            List<DataObject> dataObjects = new List<DataObject>();

            Message = new AMBMessage(byteArray);

            this.MessageType = (AMBMessageType)Message.TypeLSB;

            foreach (byte[] arr in Message.DataRecords)
            {
                DataObject dataObject = new DataObject();

                dataObject.DataType = arr[0];
                dataObject.DataLength = arr[1];
                dataObject.Data = arr.Skip(arr.Length - dataObject.DataLength).ToArray();

                if (dataObject.DataLength > 0)
                    dataObjects.Add(dataObject);
                
            }
           
            this.Data = dataObjects;
        }
    }

    public class DataObject
    {
        public DataObject()
        {
        }

        public int DataType
        {
            get;
            set;
        }

        public DataObject(int dataType, int dataLength, byte[] data)
        {
            this.DataLength = dataLength;
            this.DataType = dataType;
            this.Data = data;
        }

        public int DataLength { get; set; }

        public byte[] Data { get; set; }

    }
}
